home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Online / x3270 / unix_files / Examples / cms_logon.bash < prev    next >
Encoding:
Text File  |  2008-09-03  |  2.2 KB  |  144 lines

  1. #! /usr/local/bin/bash
  2.  
  3. # Copyright 1995, 2000 by Paul Mattes.
  4. #  Permission to use, copy, modify, and distribute this software and its
  5. #  documentation for any purpose and without fee is hereby granted,
  6. #  provided that the above copyright notice appear in all copies and that
  7. #  both that copyright notice and this permission notice appear in
  8. #  supporting documentation.
  9.  
  10. # VM login script, which runs as a peer of x3270.
  11. # bash version
  12.  
  13. set -x
  14. me=${0##*/}
  15.  
  16. # Set up login parameters
  17. tcp_host=${1-ibmsys}
  18. userid=${2-USERID}
  19. password=${3-PASSWORD}
  20.  
  21. # Verbose flag for x3270if
  22. #v="-v"
  23.  
  24. # Define some handly local functions.
  25.  
  26. # x3270 interface function
  27. function xi
  28. {
  29.     X3270OUTPUT=6 X3270INPUT=5 x3270if 5>$ip 6<$op $v "$@"
  30. }
  31.  
  32. # 'xi' function, with space-to-comma translation
  33. function xic
  34. {
  35.     typeset sep cmd="$1("
  36.  
  37.     shift
  38.     while [ $# -gt 0 ]
  39.     do    cmd="$cmd$sep\"$1\""
  40.         sep=","
  41.         shift
  42.     done
  43.     cmd="$cmd)"
  44.     xi "$cmd"
  45. }
  46.  
  47. # Common x3270 Ascii function
  48. function ascii
  49. {
  50.     xic Ascii $@
  51. }
  52.  
  53. # Common x3270 String function
  54. function string
  55. {
  56.     xic String "$@"
  57. }
  58.  
  59. # x3270 connection status
  60. function cstatus
  61. {
  62.     xi -s 4
  63. }
  64.  
  65. # x3270 rows
  66. function rows
  67. {
  68.     xi -s 7
  69. }
  70.  
  71. # x3270 columns
  72. function cols
  73. {
  74.     xi -s 8
  75. }
  76.  
  77. # x3270 Snap function
  78. function snap
  79. {
  80.     xic Snap $@
  81. }
  82.  
  83. # Failure.
  84. function die
  85. {
  86.     xic Info "$me error: $@"
  87.     xic CloseScript 1
  88.     exit 1
  89. }
  90.  
  91. # Wait for a READ prompt.
  92. function waitread
  93. {
  94.     snap
  95.     while [ "$(snap Ascii $(expr $(snap Rows) - 1) $(expr $(snap Cols) - 17) 4)" != "READ" ]
  96.     do    xic Wait Output
  97.         snap
  98.     done
  99. }
  100.  
  101. # Set up pipes for x3270 I/O
  102. ip=/tmp/ip.$$
  103. op=/tmp/op.$$
  104. rm -f $ip $op
  105. trap "rm -f $ip $op" EXIT
  106. trap "exit" INT QUIT HUP TERM
  107. mkfifo $ip $op
  108.  
  109. # Start x3270
  110. x3270 -script -model 2 <$ip >$op &
  111. xp=$!
  112. exec 5>$ip    # hold the pipe open
  113. xi -s 0 >/dev/null || exit 1
  114.  
  115. # Connect to host
  116. xic Connect $tcp_host || die "Connection failed."
  117.  
  118. # Make sure we're connected.
  119. xic Wait InputField
  120. [ "$(cstatus)" = N ] && die "Not connected."
  121.  
  122. # Log in.
  123. string "$userid"
  124. xic Tab
  125. string "$password"
  126. xic Enter
  127. waitread
  128. if [ "$(ascii 1 11 7)" = "Already" ]
  129. then    die "Can't run -- already logged in."
  130.     exit 1
  131. fi
  132.  
  133. # Boot CMS, if we have to.
  134. if [ "$(ascii $(expr $(rows) - 1) $(expr $(cols) - 20) 2)" = "CP" ]
  135. then    xic Clear
  136.     string "i cms"
  137.     xic Enter
  138.     waitread
  139. fi
  140.     
  141. # Done.
  142. xic CloseScript
  143. exit 0
  144.